package cn.chinaiptv.utils;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import cn.chinaiptv.bean.PlatformParamsBean;

/**
 * 解析平台参数信息的工具类
 * 
 * @author Admin
 *
 */
public class PlatformParamUtils {

	/**
	 * 平台参数配置文件解析的工具类
	 * 
	 * @param filename
	 * @return
	 */
	public static HashMap<String, PlatformParamsBean> getplatform(
			String filename) {
		HashMap<String, PlatformParamsBean> platforms = new HashMap<String, PlatformParamsBean>();
		InputStream in = PlatformParamUtils.class.getClassLoader()
				.getResourceAsStream(filename);
		try {
			SAXReader reader = new SAXReader();
			Document document = reader.read(in);
			Element root = document.getRootElement();
			Iterator<Element> elementIterator = root.elementIterator();
			while (elementIterator.hasNext()) {
				Element object = elementIterator.next();
				Iterator<Element> platformparam = object.elementIterator();
				String platfromsStr = platformparam.next().getText();
				String cspid = platformparam.next().getText();
				String lspid = platformparam.next().getText();
				PlatformParamsBean bean = new PlatformParamsBean(platfromsStr,
						cspid, lspid);
				platforms.put(platfromsStr, bean);
			}
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return platforms;
	}
}
